#!/bin/bash

#init
mkdir ~/linlab3 2> /dev/null && cd ~/linlab3

# 1 ---
mkdir logs

# 2 ---
grep '^(EE)' -hr /var/log 2> /dev/null > errors.log

# 3 ---
# perl regexp mode
cat errors.log | grep -P '[\w.]+$'

# 4 ---
#cat /var/log/Xorg.0.log | grep -P '\(II\)|\(\*\*\)' | sed s/\(II\)/CRAP/g
#cat /var/log/Xorg.0.log | sed -E 's/\(II\)/CRAP:/g;s/\(\*\*\)/OHNOES!:/g'
cat /var/log/Xorg.0.log | sed -n '/^(\*/ p; /^(I/ p' | sed -E 's/\(II\)/WARNING:/g;s/\(\*\*\)/ERROR:/g;s/\(.*//g' | sort > logs/full.log

# 5 ---
#[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
grep -PhroI '[a-zA-z0-9]+@([a-zA-Z0-9]+\.)+[a-zA-Z]{2,3}' /etc 2> /dev/null | uniq

# 6 ---
grep -PhroI '[a-zA-z0-9]+@([a-zA-Z0-9]+\.)+[a-zA-Z]{2,3}' /etc 2> /dev/null | uniq | tr '\n' ',' > emails.list

# 7 ---
grep -rhP '^#!/bin/\w+' /bin/ | sort | uniq --count | head -n 1 | awk -F"/" '{ print $3 " - is the most popular interpreter" }'



